package com.group4.admin.beans;

import com.group4.entity.Course;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.event.ActionEvent;

/**
 * Controlles adminCourses.xhtml
 * 
 * @author andake, anjonas
 */
@ManagedBean
@RequestScoped
public class AdminCoursesControllerBean {
    
    @ManagedProperty(value="#{adminCoursesBackingBean}")
    AdminCoursesBackingBean cb;

    /** Creates a new instance of AdminCoursesControllerBean */
    public AdminCoursesControllerBean() {
    }

    public AdminCoursesBackingBean getCb() {
        return cb;
    }

    public void setCb(AdminCoursesBackingBean cb) {
        this.cb = cb;
    }
    
    // listens for edit/add course event
    public void editAddCourse() {
        System.out.print(cb.getEditId());
        if (!cb.getEditId().isEmpty())
            cb.editCourse();
        else
            cb.addCourse();
    }
    
    // listens for remove course event
    public void removeCourse(ActionEvent e) {
        Course c = (Course) e.getComponent().getAttributes().get("course");
        cb.removeCourse(c);
    }
}
